//
//  NewsCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 15/12/21.
//  Copyright © 2015年 game. All rights reserved.
//

#import "NewsCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#define AddsubView(view) [self.contentView addSubview:view]

@interface NewsCell ()

@property (nonatomic,strong) UIView *linView;

@end
@implementation NewsCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        [self CrectImage];
        [self CreatTitle];
        _time = [self CrecTimeAndClikNumbWhithLabel:_time AndRect:CGRectMake(Width(_image)+25, Height(_image)-17, 120, 20)];
        _time.textAlignment = NSTextAlignmentLeft;
        
        _clikNumb = [self CrecTimeAndClikNumbWhithLabel:_clikNumb AndRect:CGRectMake(SCREEN_WIDTH-100, Height(_image)-17,100, 20)];
        
        
        /**
         *  显示时间的那个钟
         */
       UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(Width(_image)+10, Y(_time), 12, 12)];
        view.centerY = _time.centerY;
        radius(view, W(view)/2);
        [view setImage:[UIImage imageNamed:@"clock"]];
        
        AddsubView(view);
        _cellHight = Height(_image)+10;
        
        self.height = _cellHight;
    }
    return self;
}

-(void)setModel:(NEWAticListModel *)model{

    _model = model;
   
    [self.image sd_setImageWithURL:[NSURL URLWithString:model.litpic]];
    
    self.title.text = model.title;
    self.time.text=model.pubdate;
    self.clikNumb.text =model.click;
    self.AticleID = model.AtcID;
    
    self.skin = model.skin;
    if (model.skin.intValue==1) {
        
        [self.image.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        UIImageView *VideoImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"video"]];
        [self.image addSubview:VideoImg];
        [VideoImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.image.mas_centerX);
            make.centerY.equalTo(self.image.mas_centerY);
            make.height.equalTo(self.image.mas_height);
            make.width.equalTo(self.image.mas_width);
        }];
    }
    
    [_linView removeFromSuperview];
    _linView = [[UIView alloc]initWithFrame:CGRectMake(0, _cellHight-0.5, SCREEN_WIDTH, 0.5)];
    
    _linView.backgroundColor = linColor;
    [self.contentView addSubview:_linView];

}

-(void)CrectImage{
    _image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH*0.33, (SCREEN_WIDTH*0.33)*0.625)];
        AddsubView(_image);
   
}
-(void)CreatTitle{
    _title = [[UILabel alloc]init];
    
    _title.font = font(SCREEN_WIDTH*0.045);
    _title.numberOfLines = 2;
    _title.alpha = 0.8;
    AddsubView(_title);
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@7);
        make.left.equalTo(_image.mas_right).offset(10);
        make.right.equalTo(@-10);
    }];

}

-(UILabel *)CrecTimeAndClikNumbWhithLabel:(UILabel *)label AndRect:(CGRect)rect{

    label = [[UILabel alloc]initWithFrame:rect];
    label.font = font(SCREEN_WIDTH*0.032);
    label.tintColor = [UIColor grayColor];
    label.alpha = 0.4;
    label.textAlignment = NSTextAlignmentCenter;
    AddsubView(label);
    return label;
}

@end
